<template>
  <div>
    数据统计
    <div id="main"></div>
  </div>
</template>

<script setup>
import * as echarts from "echarts";
import { onMounted } from "vue-demi";
import service from "../../until/service";

onMounted(() => {
  const chartDom = document.getElementById("main");
  const myChart = echarts.init(chartDom);
  service
    .get("reports/type/1")
    .then((res) => {
      console.log(res.data);
      const { legend, series, xAxis } = res.data.data;
      console.log(legend, series, xAxis);
      const option = {
        title: {
          text: "Stacked Area Chart",
        },
        tooltip: {
          trigger: "axis",
          axisPointer: {
            type: "cross",
            label: {
              backgroundColor: "#6a7985",
            },
          },
        },
        legend: {
          data: legend.data,
        },
        toolbox: {
          feature: {
            saveAsImage: {},
          },
        },
        grid: {
          left: "3%",
          right: "4%",
          bottom: "3%",
          containLabel: true,
        },
        xAxis: [
          {
            type: "category",
            boundaryGap: false,
            data: xAxis[0].data,
          },
        ],
        yAxis: [
          {
            type: "value",
          },
        ],
        series: series,
      };
      console.log(option);
      option && myChart.setOption(option);
    })
    .catch((error) => console.log(error));
});
</script>

<style scoped>
#main {
  width: 900px;
  height: 400px;
}
</style>